package br.com.ac.fatureweb.utilitary;

import java.security.MessageDigest;
import java.util.Base64;

import org.jboss.security.Base64Encoder;

public final class Criptografia {

	public static String executeMd5(final String senha) {
		try {
			final byte[] mensagem = senha.getBytes();

			final MessageDigest md = MessageDigest.getInstance("MD5");

			md.update(mensagem);

			final byte[] gerado = md.digest();

			final String retorno = Base64Encoder.encode(gerado);

			return retorno;

		} catch (final Exception e) {
			return null;
		}
	}

	public static String executeSha(final String password) {
		try {
			MessageDigest md = MessageDigest.getInstance("SHA-256");

			byte[] passwordBytes = password.getBytes();

			byte[] hash = md.digest(passwordBytes);

			String passwordHash = Base64.getEncoder().encodeToString(hash);

			return passwordHash;
			
		} catch (Exception ex) {
			return null;
		}
	}
	
	public static void main(String[] args) {
		System.out.println(executeSha("admin"));
	}
}
